home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7896 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: news.lpr.carel.fi!usenet
  2. From: Ari Lukumies <aril@cmt.lpr.mail.carel.fi>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Explain this> %s \"%[^\"]\"
  5. Date: Thu, 29 Feb 1996 17:07:13 +0200
  6. Organization: Carelcomp Forest
  7. Message-ID: <3135C121.5E6B@cmt.lpr.mail.carel.fi>
  8. References: <4h2t6u$v56@useneta1.news.prodigy.com>
  9. NNTP-Posting-Host: renoir.cclahti.carel.fi
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (WinNT; I)
  14.  
  15. David Cunningham wrote:
  16. > I have a file that contains text like this:
  17. > 012345678     "Joe  Smith"
  18. > I also have an example of sscanf to pick out these fields. Can someone
  19. > translate what  \"%[^\"]\"%d"  means. I need to have a good understanding
  20. > of this for a homework assignment. It looks like this:
  21. > sscanf(buff,"%s \ "%[^\"]\" %d",student_list->ss_num,student_list->name);
  22. > Please explain what these hieroglyphics mean, character by character.
  23. > The sscanf will produce this--> 012345678  Joe Smith
  24.  
  25. What you wrote in the sscanf statement above, produces a syntax error and will not 
  26. compile. You probably meant this format string:
  27.  
  28.     "%s \"%[^\"]\"%d"
  29.  
  30. Anyway, inside a format string the escape sequence \" means that the string contains a 
  31. quotation mark (it doesn't here mark the end of the string). The construct %[^\"] means 
  32. that the string is read until the first character that appears in the character set (ie. 
  33. a quotation mark here). If it read %[\"], the string would be read until the first 
  34. character that does _not_ appear in the character set. I'll pass the remark that your 
  35. program will not run correctly, if you write the sscanf function call this way. Anyway, 
  36. you may find better approach. Skim through the online helps for 'Format Specification 
  37. Fields' or take a look at a good book. That should help you through your homework 
  38. assignment. :)
  39.  
  40.  
  41. Later,
  42.  AriL
  43. -- 
  44. All my opinions are mine and mine alone.
  45.